<!--
 * @Description: 导出工具
 * @Author: cgt
 * @Date: 2021-12-10 14:42:00
 * @LastEditors: cgt
 * @LastEditTime: 2021-12-28 19:56:30
-->
<template>
  <div>
    <el-button type="primary" @click="initParam">初始化参数</el-button>
    <el-form label-position="top">
      <el-form-item label="输出格式">
        <el-select v-model="format" placeholder="输出格式" value-key="value">
          <el-option v-for="(item,idx) in formats" :key="idx" :label="item.label" :value="item"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="输出纸张大小">
        <el-select v-model="size" placeholder="输出纸张大小" value-key="value">
          <el-option v-for="(item,idx) in sizes" :key="idx" :label="item.label" :value="item"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="单位">
        <el-select v-model="unit" placeholder="单位" value-key="value">
          <el-option v-for="(item,idx) in units" :key="idx" :label="item.label" :value="item"> </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="doExport">导出</el-button>
  </div>
</template>

<script>
import mixins from '../mixins';
export default {
  name: 'ExportTool',
  props: {
    getTool: {
      type: Function,
      required: true
    }
  },
  mixins: [mixins],
  data() {
    return {
      format: '',
      formats: [],
      size: '',
      sizes: [],
      unit: '',
      units: []
    };
  },
  mounted() {
  },
  methods: {
    initParam() {
      this.formats = this.obj2arr(this.getTool('ExportTool').Format);
      this.sizes = this.obj2arr(this.getTool('ExportTool').Size);
      this.units = this.obj2arr(this.getTool('ExportTool').Unit);
      this.format = this.formats[2];
      this.size = this.sizes[2];
      this.unit = this.units[1];
      console.log('vm', this);
    },
    obj2arr(obj) {
      var keys = Object.keys(obj);
      return keys.map((key) => {
        var rtn = {};
        rtn.label = key;
        rtn.value = obj[key];
        return rtn;
      });
    },
    doExport() {
      this.getTool('ExportTool').export({

        size: this.size.value,
        format: this.format.value,
        unit: this.unit.value
      });
    }
  }
};
</script>

<style></style>
